package com.zahb.qadx.ui.activity;

import android.os.Bundle;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.zahb.qadx.R;
import com.zahb.qadx.base.BaseActivity;
import com.zahb.qadx.model.OfflinePlanBean;
import com.zahb.qadx.ui.fragment.HandoutFragment;
import com.zahb.qadx.ui.fragment.LecturerFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class OfflineTrainDetailActivity extends BaseActivity {
    @BindView(R.id.tab_layout_train)
    TabLayout mTabLayout;
    @BindView(R.id.view_pager2_train)
    ViewPager2 mViewPager2;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvHour)
    TextView tvHour;
    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.tvDes)
    TextView tvDes;

    private List<String> mTitles = new ArrayList<>();
    private List<Fragment> fragmentList = new ArrayList<>();
    int teacherId=0;
    @Override
    protected int getLayout() {
        return R.layout.activity_offline_train_detail;
    }

    @Override
    protected void initViews() {
        mUnbinder = ButterKnife.bind(this);



        OfflinePlanBean.RecordsEntity trainDetailsBean = getIntent().getParcelableExtra("data");

        teacherId = trainDetailsBean.getTeacherId();
        int classId = trainDetailsBean.getClassId();
        int planId = trainDetailsBean.getPlanId();


        mUnbinder = ButterKnife.bind(this);


        if (trainDetailsBean != null) {
            tvName.setText(trainDetailsBean.getPlanName());
            tvHour.setText(("学时: "+trainDetailsBean.getLearnHoursStr()));
            tvTime.setText("时间: "+trainDetailsBean.getStartTime()+ " ~ " +trainDetailsBean.getEndTime());
            tvDes.setText("地点: "+trainDetailsBean.getPlanAddress());
        }

        HandoutFragment handoutFragment = new HandoutFragment();
        fragmentList.add(handoutFragment);
        Bundle two = new Bundle();
        two.putInt("data", 1);
        two.putInt("id", classId);
        two.putInt("planId", planId);
        handoutFragment.setArguments(two);
        mTitles.add("查看讲义");

        LecturerFragment lecturerFragment = new LecturerFragment();
        fragmentList.add(lecturerFragment);
        Bundle bundle = new Bundle();
        bundle.putInt("teacherId", teacherId);
        lecturerFragment.setArguments(bundle);
        mTitles.add("讲师介绍");

        mViewPager2.setAdapter(new TrainDetailsActivity.TrainListFragmentAdapter(this, fragmentList));
        if(fragmentList.size()>1)
            mViewPager2.setOffscreenPageLimit(fragmentList.size() - 1);
        TabLayoutMediator mediator = new TabLayoutMediator(mTabLayout, mViewPager2,
                (tab, position) -> tab.setText(mTitles.get(position)));
        mediator.attach();
    }

    @Override
    protected int getTitleStringRes() {
        return R.string.offline_train_detail;
    }

}
